package com.ruoyi.dzzh.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dzzh.domain.DzzhPhone;
import com.ruoyi.dzzh.service.IDzzhPhoneService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 短信群发Controller
 * 
 * @author cjt
 * @date 2022-05-19
 */
@RestController
@RequestMapping("/dzzh/phone")
public class DzzhPhoneController extends BaseController
{
    @Autowired
    private IDzzhPhoneService dzzhPhoneService;

    /**
     * 查询短信群发列表
     */
    @PreAuthorize("@ss.hasPermi('dzzh:phone:list')")
    @GetMapping("/list")
    public TableDataInfo list(DzzhPhone dzzhPhone)
    {
        startPage();
        List<DzzhPhone> list = dzzhPhoneService.selectDzzhPhoneList(dzzhPhone);
        return getDataTable(list);
    }

    /**
     * 导出短信群发列表
     */
    @PreAuthorize("@ss.hasPermi('dzzh:phone:export')")
    @Log(title = "短信群发", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DzzhPhone dzzhPhone)
    {
        List<DzzhPhone> list = dzzhPhoneService.selectDzzhPhoneList(dzzhPhone);
        ExcelUtil<DzzhPhone> util = new ExcelUtil<DzzhPhone>(DzzhPhone.class);
        util.exportExcel(response, list, "短信群发数据");
    }

    /**
     * 获取短信群发详细信息
     */
    @PreAuthorize("@ss.hasPermi('dzzh:phone:query')")
    @GetMapping(value = "/{phoneId}")
    public AjaxResult getInfo(@PathVariable("phoneId") Long phoneId)
    {
        return AjaxResult.success(dzzhPhoneService.selectDzzhPhoneByPhoneId(phoneId));
    }

    /**
     * 新增短信群发
     */
    @PreAuthorize("@ss.hasPermi('dzzh:phone:add')")
    @Log(title = "短信群发", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DzzhPhone dzzhPhone)
    {
        return toAjax(dzzhPhoneService.insertDzzhPhone(dzzhPhone));
    }

    /**
     * 修改短信群发
     */
    @PreAuthorize("@ss.hasPermi('dzzh:phone:edit')")
    @Log(title = "短信群发", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DzzhPhone dzzhPhone)
    {
        return toAjax(dzzhPhoneService.updateDzzhPhone(dzzhPhone));
    }

    /**
     * 删除短信群发
     */
    @PreAuthorize("@ss.hasPermi('dzzh:phone:remove')")
    @Log(title = "短信群发", businessType = BusinessType.DELETE)
	@DeleteMapping("/{phoneIds}")
    public AjaxResult remove(@PathVariable Long[] phoneIds)
    {
        return toAjax(dzzhPhoneService.deleteDzzhPhoneByPhoneIds(phoneIds));
    }
}
